package com.example.guiguihomemedical.mapper;

import com.example.guiguihomemedical.entity.Fulfillment;
import com.example.guiguihomemedical.entity.Serviceitems;
import com.example.guiguihomemedical.entity.dto.FulfillmentviewData;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface FulfillmentMapper {
    @Select("SELECT * FROM fulfillment")
    List<Fulfillment> findAllFulfillment();
    @Select("SELECT * FROM fulfillmentdescription where idcard=#{idcard} AND service_packages_id =#{servicePackagesId} AND service_item_id =#{serviceItemId} AND signingid =#{signingid}")
    List<FulfillmentviewData> findByPrimaryFulfillment(int servicePackagesId, int serviceItemId, String idcard , int signingid);
    @Insert("INSERT INTO fulfillment (service_packages_id, service_item_id,idcard,completions,fulfillment_time,fulfillment_nexttime,fulfillment_contract,fulfillment_efficiency,signingid) VALUES (#{servicePackagesId},#{serviceItemId},#{idcard},#{completions},#{fulfillmentTime},#{fulfillmentNexttime},#{fulfillmentContract},#{fulfillmentEfficiency},#{signingid})")
    void insertFulfillment(Fulfillment fulfillment);

    @Delete("delete from fulfillment where signingid = #{signingid}")
    void deleteTrueId(int signingid);
    @Select("SELECT COUNT(*) AS total_count FROM fulfillmentdescription where idcard=#{idcard} AND service_packages_id =#{servicePackagesId} AND service_item_id =#{serviceItemId} AND signingid =#{signingid}")
    int findFulfillmentItemTotal(int servicePackagesId, int serviceItemId, String idcard , int signingid);

    @Select("SELECT MAX(fulfillment_nexttime) AS max_nexttime FROM fulfillmentdescription where idcard=#{idcard} AND service_packages_id =#{servicePackagesId} AND service_item_id =#{serviceItemId} AND signingid =#{signingid}")
    Date findFulfillmentItemMaxNextTime(int servicePackagesId, int serviceItemId, String idcard ,int signingid);
}
